const mysql = require('mysql')
const con = mysql.createConnection({
  host: 'localhost',
  user: 'root',
  password: '123456789',
  port: '3306',
  database: 'myblog'
})

con.connect()
// 执行sql
const sql = `INSERT INTO blogs(title, content, createtime, author) VALUES('标题5', '123', 1614244178, 'lisi')`
// const sql = `UPDATE blogs set author='zhangsan' where id=4`
con.query(sql,(err, result) => {
  if (err) {
    console.error(err)
    con.end()
    return
  }
  console.log(result)
})

// 关闭连接
con.end()